package com.frostmourne.mxsattributeinventory.hooks;

import com.frostmourne.mxsattributeinventory.MXSAttributeInventory;
import github.saukiya.sxattribute.SXAttribute;
import github.saukiya.sxattribute.data.attribute.SXAttributeData;
import github.saukiya.sxattribute.data.condition.SXConditionType;
import org.bukkit.entity.Player;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class SXHook {

    public static Map<Player , Map<String , List<String>>> playerAttrMap = new HashMap<>();

    public static void setAttr(String invName, Player player, List<String> attr){
        Map<String,List<String>> dataMap;
        if (playerAttrMap.containsKey(player)){
            dataMap = playerAttrMap.get(player);
        }else{
            dataMap = new HashMap<>();
        }
        dataMap.put(invName,attr);
        playerAttrMap.put(player,dataMap);
        refreshAttr(player);
    }

    public static void refreshAttr(Player player){
        Map<String,List<String>> dataMap;
        dataMap = playerAttrMap.get(player);
        List<String> str = new ArrayList<>();
        for (String s : dataMap.keySet()){
            str.addAll(dataMap.get(s));
        }
        SXAttributeData sad = SXAttribute.getApi().getLoreData(player,SXConditionType.ALL,str);
        SXAttribute.getApi().setEntityAPIData(MXSAttributeInventory.class,player.getUniqueId(),sad);

    }

}
